package  com.pcbly.web.business.crm;

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.persistence.crm.CgthdDao;
import com.pcbly.web.persistence.table.ColumnDao;
import com.pcbly.web.bean.crm.CgthdBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;

 
public class CgthdServiceImp extends BaseServiceImp<CgthdBean> implements CgthdService {
	 public CgthdServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}
	private CgthdDao cgthdDao;
	
	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	
	public void setCgthdDao(CgthdDao cgthdDao) {
		this.cgthdDao = cgthdDao;
	}
	
	@Override
	public CgthdBean getCgthdBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return cgthdDao.get(CgthdBean.class,id);
	}
	
	@Override
	public void removeCgthdBeanById(String id) throws Exception{
		cgthdDao.removeCgthdBeanById(id);
	}
	
	@Override
	public void removeCgthdBeanByIds(String ids) throws Exception{
		cgthdDao.removeCgthdBeanByIds(ids);
	}
	
	
	@Override
	public CgthdBean saveCgthdBean(CgthdBean crm) throws Exception{
		return cgthdDao.saveCgthdBean(crm);
	}
	
	@Override
	public CgthdBean updateCgthdBean(CgthdBean crm) throws Exception{
		cgthdDao.saveObject( crm);
		return crm;
	}
	public Page<CgthdBean>  findCgthdBeanByCond(CgthdBean bean,
			Page<CgthdBean> page, String orderByName, boolean asc)
			throws Exception{
		return cgthdDao.findCgthdBeanByCond(
				bean, page, orderByName, asc);
	}
	
	@Override
	public String findCgthdBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findCgthdBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = cgthdDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findCgthdBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = cgthdDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveCgthdBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		cgthdDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasCgthdBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return cgthdDao.getHasCommnonDataBeanExt(tableName, id);
	}
}
